package com.android.fragmentdemo.defineviews
import android.content.Context
import android.graphics.Canvas
import android.util.AttributeSet
import androidx.appcompat.widget.LinearLayoutCompat
import androidx.core.content.res.ResourcesCompat
import com.android.fragmentdemo.R

class DrawBmpViewLayout @JvmOverloads constructor(
    context: Context,
    attributeSet: AttributeSet? = null
) : LinearLayoutCompat(context, attributeSet) {

    override fun dispatchDraw(canvas: Canvas) {

        canvas.drawColor(context.resources.getColor(R.color.color_C5C9CC))

        val drawable = ResourcesCompat.getDrawable(context.resources, R.drawable.b11, null)
        drawable?.apply {
            setBounds(0, 0, /*intrinsicWidth*/measuredWidth, intrinsicHeight)
            draw(canvas)
        }

        drawable?.apply {
            setBounds(0, measuredHeight / 2, intrinsicWidth, intrinsicHeight + measuredHeight / 2)
            draw(canvas)
        }

        try {
            super.dispatchDraw(canvas)
        } catch (ex: Exception) {
            ex.printStackTrace()
        }
    }
}